import React, { Component } from 'react'
import PropTypes from 'prop-types'
import './index.css'

export default class Item extends Component {

  static propTypes={
    id:PropTypes.string.isRequired,
    content:PropTypes.string.isRequired,
    isDone:PropTypes.bool.isRequired,
    changeTodo:PropTypes.func.isRequired,
    deleteItem:PropTypes.func.isRequired,
  }

  changeTodo=()=>{
    const { id,changeTodo } = this.props
    return (e)=>{
      changeTodo(id,e.target.checked)
    }
  }

  render() {
    const { id,isDone,content,deleteItem } = this.props
    return (
      <div className='item' >
        <label className='radio'><input ref='checkbox' type="checkbox" checked={isDone} onChange={this.changeTodo()}/></label>
        <div className='content'>{content}</div>
        <div className='delete_btn' onClick={()=>deleteItem(id)}>删除</div>
      </div>
    )
  }
}
